/// 统计摘要数据模型
/// Statistics summary data model
class StatisticsSummary {
  /// 总记录数
  /// Total record count
  final int totalRecords;
  
  /// 本周记录数
  /// This week record count
  final int weekRecords;
  
  /// 平均情绪强度
  /// Average emotion intensity
  final double averageIntensity;
  
  /// 最常见的情绪类型
  /// Most common emotion type
  final String mostCommonEmotion;
  
  /// 最常见情绪的次数
  /// Count of most common emotion
  final int mostCommonEmotionCount;
  
  /// 情绪分布统计
  /// Emotion distribution statistics
  final Map<String, int> emotionDistribution;
  
  /// 本周情绪趋势
  /// This week emotion trend
  final List<DailyEmotionSummary> weeklyTrend;
  
  /// 统计时间范围开始
  /// Statistics time range start
  final DateTime startDate;
  
  /// 统计时间范围结束
  /// Statistics time range end
  final DateTime endDate;

  const StatisticsSummary({
    required this.totalRecords,
    required this.weekRecords,
    required this.averageIntensity,
    required this.mostCommonEmotion,
    required this.mostCommonEmotionCount,
    required this.emotionDistribution,
    required this.weeklyTrend,
    required this.startDate,
    required this.endDate,
  });

  /// 从JSON创建实例
  /// Create instance from JSON
  factory StatisticsSummary.fromJson(Map<String, dynamic> json) {
    return StatisticsSummary(
      totalRecords: json['total_records'] as int,
      weekRecords: json['week_records'] as int,
      averageIntensity: (json['average_intensity'] as num).toDouble(),
      mostCommonEmotion: json['most_common_emotion'] as String,
      mostCommonEmotionCount: json['most_common_emotion_count'] as int,
      emotionDistribution: Map<String, int>.from(json['emotion_distribution'] as Map),
      weeklyTrend: (json['weekly_trend'] as List)
          .map((item) => DailyEmotionSummary.fromJson(item as Map<String, dynamic>))
          .toList(),
      startDate: DateTime.fromMillisecondsSinceEpoch(json['start_date'] as int),
      endDate: DateTime.fromMillisecondsSinceEpoch(json['end_date'] as int),
    );
  }

  /// 转换为JSON
  /// Convert to JSON
  Map<String, dynamic> toJson() {
    return {
      'total_records': totalRecords,
      'week_records': weekRecords,
      'average_intensity': averageIntensity,
      'most_common_emotion': mostCommonEmotion,
      'most_common_emotion_count': mostCommonEmotionCount,
      'emotion_distribution': emotionDistribution,
      'weekly_trend': weeklyTrend.map((item) => item.toJson()).toList(),
      'start_date': startDate.millisecondsSinceEpoch,
      'end_date': endDate.millisecondsSinceEpoch,
    };
  }

  /// 复制并修改部分属性
  /// Copy with modified properties
  StatisticsSummary copyWith({
    int? totalRecords,
    int? weekRecords,
    double? averageIntensity,
    String? mostCommonEmotion,
    int? mostCommonEmotionCount,
    Map<String, int>? emotionDistribution,
    List<DailyEmotionSummary>? weeklyTrend,
    DateTime? startDate,
    DateTime? endDate,
  }) {
    return StatisticsSummary(
      totalRecords: totalRecords ?? this.totalRecords,
      weekRecords: weekRecords ?? this.weekRecords,
      averageIntensity: averageIntensity ?? this.averageIntensity,
      mostCommonEmotion: mostCommonEmotion ?? this.mostCommonEmotion,
      mostCommonEmotionCount: mostCommonEmotionCount ?? this.mostCommonEmotionCount,
      emotionDistribution: emotionDistribution ?? this.emotionDistribution,
      weeklyTrend: weeklyTrend ?? this.weeklyTrend,
      startDate: startDate ?? this.startDate,
      endDate: endDate ?? this.endDate,
    );
  }

  @override
  String toString() {
    return 'StatisticsSummary(totalRecords: $totalRecords, weekRecords: $weekRecords, averageIntensity: $averageIntensity)';
  }
}

/// 每日情绪摘要
/// Daily emotion summary
class DailyEmotionSummary {
  /// 日期
  /// Date
  final DateTime date;
  
  /// 记录数量
  /// Record count
  final int recordCount;
  
  /// 平均情绪强度
  /// Average emotion intensity
  final double averageIntensity;
  
  /// 主要情绪类型
  /// Primary emotion type
  final String? primaryEmotion;

  const DailyEmotionSummary({
    required this.date,
    required this.recordCount,
    required this.averageIntensity,
    this.primaryEmotion,
  });

  /// 从JSON创建实例
  /// Create instance from JSON
  factory DailyEmotionSummary.fromJson(Map<String, dynamic> json) {
    return DailyEmotionSummary(
      date: DateTime.fromMillisecondsSinceEpoch(json['date'] as int),
      recordCount: json['record_count'] as int,
      averageIntensity: (json['average_intensity'] as num).toDouble(),
      primaryEmotion: json['primary_emotion'] as String?,
    );
  }

  /// 转换为JSON
  /// Convert to JSON
  Map<String, dynamic> toJson() {
    return {
      'date': date.millisecondsSinceEpoch,
      'record_count': recordCount,
      'average_intensity': averageIntensity,
      'primary_emotion': primaryEmotion,
    };
  }

  /// 复制并修改部分属性
  /// Copy with modified properties
  DailyEmotionSummary copyWith({
    DateTime? date,
    int? recordCount,
    double? averageIntensity,
    String? primaryEmotion,
  }) {
    return DailyEmotionSummary(
      date: date ?? this.date,
      recordCount: recordCount ?? this.recordCount,
      averageIntensity: averageIntensity ?? this.averageIntensity,
      primaryEmotion: primaryEmotion ?? this.primaryEmotion,
    );
  }

  @override
  String toString() {
    return 'DailyEmotionSummary(date: $date, recordCount: $recordCount, averageIntensity: $averageIntensity)';
  }
}